<?php
			
	/* SVN FILE: $Id: view.php 22 2011-03-21 17:00:29Z michele.andreoletti@gmail.com $ */
	
	/**
	 * Project Name : arcadia
	 *
	 * @author $Author: michele.andreoletti@gmail.com $
	 * @version $Revision: 22 $
	 * @lastrevision $Date: 2011-03-21 17:00:29 +0000 (Mon, 21 Mar 2011) $
	 * @filesource $URL: http://arcadia.googlecode.com/svn/trunk/budget/view.php $
	 */

	require_once 'include/functions.php';
	require_once 'include/const.inc.php';
	require_once '../include/auth.inc.php';
	require_once '../include/conn.inc.php';

	require_once('../include/view.php');

	if (!empty($iView)) {
	  	$sHeaderTitle = $sAPP_NAME." &raquo; ".$aData['sUnita']." &raquo; ".$aData['sApparecchiatura'];
	  	$sTableTitle = "<div style='font-size: 0.7em'>".$aData['sUnita']."</div><div>".$aData['sApparecchiatura']."</div>";
	} else  {
		$sHeaderTitle = $sAPP_NAME." &raquo; $sTableTitle";
	}
	
	$html .= "<div id='tabs'><ul>$sTabsHtml</ul>";

	$i = 1;
	if (is_allowed('view', fnFieldAccessLvl($iAccessLvl, $i))) {

		$html .= "<div id='tabs-$i'>";

			$html .= ($sAction == 'edit' ? "<form method='post' id='form-tab-$i' class='buttons' action='transact.php'>" : '');
			$html .= "<table class='standard' border='".fnTableBorder()."' width='98%'>";

				$html .= "<col width='25%'><col width='25%'><col width='25%'><col width='25%'>";
				$html .= "<tbody>";

				$html .= "<tr><td>&nbsp;</td><td colspan='3' id='tags'>".fnTagsView('view', $iView, $sViewItemLink, '', '', $sAPP, false, ($iView==0 || $aData['iTrash']==1 ? false : true), true)."</td></tr>";
				$html .= "<tr><td>".fnTextInput('sRichiesta','numero richiesta',$aData,6)."</td><td>".fnTextInput('dtRichiesta','data richiesta',$aData)."</td>";

				$html .= "<td colspan='2' rowspan='7' style='vertical-align:top; padding-top:8px; padding-left:12px; padding-right:6px;'>";

					$html .= "	<table class='table-approvvigionamenti' border='".fnTableBorder()."' width='85%'>";
					$html .= "		<col width='50%'><col width='50%'>";
					$html .= "		<tr style='vertical-align: top;'><td>".fnTextInput('sOrdine','ordine',$aData,12)."</td><td>".fnTextInput('sAutorizzazione','autorizzazione',$aData,12)."</td></tr>";
					$html .= "		<tr style='vertical-align: top;'><td>".fnTextInput('dtOrdine','data ordine',$aData)."</td><td>".fnTextInput('dImporto','importo (iva inc.)',$aData,12)."</td></tr>";	
					$html .= "		<tr><td colspan='2'>&nbsp;</td></tr>";	
					$html .= "	</table>";

					$html .= "	<table class='table-approvvigionamenti' border='".fnTableBorder()."' width='85%'>";
					$html .= "		<col width='50%'><col width='50%'>";
					$html .= "		<tr style='vertical-align: top;'><td>".fnTextInput('dtFattura','data fattura',$aData)."</td><td>".fnTextInput('sFattura','numero fattura',$aData,12)."</td></tr>";
					$html .= "		<tr style='vertical-align: top;'><td colspan='2'>&nbsp;</td></tr>";	
					$html .= "	</table>";

					$html .= "	<table class='table-ingegneria' border='".fnTableBorder()."' width='85%'>";
					$html .= "		<col width='50%'><col width='50%'>";
					$html .= "		<tr style='vertical-align: top;'><td>".fnTextInput('dtCollaudo','data collaudo',$aData)."</td><td>".fnTextInput('sCollaudo','protocollo collaudo',$aData,12)."</td></tr>";
					$html .= "		<tr style='vertical-align: top;'><td colspan='2'>&nbsp;</td></tr>";	
					$html .= "	</table>";

				$html .= "</td></tr>";

				$html .= "<tr><td colspan='2'>".fnSelectInput('iDipartimento', 'dipartimento', $aData, fnSelOptionsFromResources('DIP', '1', 'iDipartimento'),'index')."</td></tr>";
				$html .= "<tr><td colspan='2'>".fnSelectInput('iUnita', 'unità', $aData, fnSelOptionsFromResources('US', '1', 'iUnita'),'index')."</td></tr>";

				$html .= "<tr><td colspan='2'>".fnTextareaInput('sApparecchiatura', 'apparecchiatura', $aData, '95%', '4.5em', false)."</td></tr>";
				$html .= "<tr><td colspan='2'>".fnTextInput('sCivab','civab',$aData,4)."</td></tr>";
				$html .= "<tr><td>".fnTextInput('sQuantita',"quantità",$aData,6)."</td>";

				$aPriorita =  array('3'=>"bassa priorità", '2'=>"media priorità", '1'=>"alta priorità", '9'=>"fuori uso");
				$html .= "<td>".(!empty($iView) ? fnColorRating('sPriorita', 'priorità', $aData, $aPriorita) : fnSelectInput('sPriorita', 'priorità', $aData, $aPriorita, 'index'))."</td></tr>";

				$html .= "<tr><td>".fnTextInput('dPreventivo','preventivo (iva inc.)',$aData, '',10,'text',1,0)."</td><td>".(!empty($iView) ? fnCheckbox('iStato','procedura in corso',$aData) : '')."</td></tr>";

				if (empty($iView) || (!empty($iView) && $sAction != 'edit' && !empty($aData['sNote'])) || (!empty($iView) && $sAction == 'edit'))	
					$html .= "<tr><td colspan='2'>".fnTextareaInput('sNote','note',$aData)."</td><td>&nbsp;</td></tr>"; 		
				
				if (empty($iView) || (!empty($iView) && $sAction != 'edit' && !empty($aData['sConsumi'])) || (!empty($iView) && $sAction == 'edit'))	
					$html .= "<tr><td colspan='2'>".fnTextareaInput('sConsumi','consumi indotti',$aData)."</td><td>&nbsp;</td></tr>"; 	

				$html .= "</tbody>";
			$html .= "</table>";

			if ($iView != 0) { 
				$html .= (isset($aData['tsCreatedWhen']) && $aData['tsCreatedWhen']!='0000-00-00 00:00:00' ? "<span class='small-text'>".fnHtmlCreatedWhen($aData['tsCreatedWhen'])."</span><br/>" : '');
				$html .= "<span class='small-text'>".fnHtmlLastModify($aData['tsLastModify'])."</span>";
			}
			
			$html .= "<div>&nbsp;</div>";
			$html .= fnButtons($iView, $i, $iAccessLvl, $aData);
			
		$html .= "</div>";
	
	}
	
	$i = 2;
	if (is_allowed('view', fnFieldAccessLvl($iAccessLvl, $i))) {

		$html .= "<div id='tabs-$i'>";		
			$html .= ($sAction=='edit' ? "<form method='post' id='form-tab-$i' class='buttons' action='transact.php'>" : '');
			$html .= "<table class='standard' border='".fnTableBorder()."' width='98%'>";
			$html .= "<col width='25%'><col width='25%'><col width='50%'>";	
			$html .= "<tr><td colspan='3'>".fnSelectInput('sClassecommissione',"classificazione",$aData,$aCLASSE_COMMISSIONE,'index')."</td></tr>";
			$html .= "<tr><td colspan='3'>".fnTextareaInput('sNotecommissione',"parere della commissione <span style='display:inline; font-size:80%;'>(valutazione clinico organizzativa, valutazione costi, valutazione benefici e valutazione tecnologica)</span>",$aData,'85%','22em',true)."</td></tr>"; 	
			$html .= "</table>";
			$html .= "<h5>&nbsp;</h5>";	
			$html .= fnButtons($iView, $i, $iAccessLvl, $aData);
		$html .= "</div>";

	}	
		
	$i = $iTabUploads;
	if (is_allowed('view', fnFieldAccessLvl($iAccessLvl, $sViewItemLink, $i))) { 
		
		$html .= "<div id='tabs-$i'>";			
			$html .= fnUploadsTabContent($iView, $sViewItemLink, $i);
		$html .= "</div>";
	
	}
		
	$html .= "</div>";
				
	// contenuto <head> della pagine
	$sHeadContent .= fnViewHeadContent($iTab, $aDisabledTabs);
		
	$bSEARCH_FORM_SHOW = false; // il form di ricerca non viene visualizzato nello script $sViewItemLink
								// non posso assegnare subito questo valore a $bSEARCH_FORM_SHOW perchè
								// alcune funzioni in ../include/view.php utilizzano questa variabile.
								
	require_once('../themes/'.$sTHEME.'/template.php');
	die();




	function fnViewHeadContent ($iTab, $aTabsDisabled) {

		global $sSUITE_NAME, $sAPP;
		
		global $iView, $sViewItemLink;
		
		global $sAction;
		
		global $sJsDocumentReady;
		
		global $aTabsLabels;
		
		$sTabsDisabled = '';
		foreach ($aTabsDisabled as $i) { $sTabsDisabled .= "$i, "; }
		$sTabsDisabled = ($sTabsDisabled!='' ? " disabled: [".substr_replace( $sTabsDisabled, "", -2 )."] " : '');

		$iTabSelected = $i = 0;
		foreach ($aTabsLabels as $sKey => $sValue) {
			if ($sKey == $iTab) { $iTabSelected = $i; }
			$i++;
		}
		
		$sSelectedTab = ($iTabSelected!=0 && !in_array($iTabSelected, $aTabsDisabled) ? ($sTabsDisabled!="" ? ", " : '') . " selected: $iTabSelected " : "");

		$sHeadContent = "

			<script type='text/javascript' charset='utf-8'>
	
				$().ready(function() {

					var oClicked = null;
					
					$sJsDocumentReady
					
					$('#tabs').tabs({ $sTabsDisabled $sSelectedTab });
				
					$('button, input:submit', '.buttons').button();

					$('#iStato').click(function() {
						oClicked = $(this);
						src = oClicked.attr('src'),
							onCheck = /\_on\.png$/,
							offCheck = /\_off\.png$/;
						fnToggle(oClicked);
					});
					
					function fnToggle (oObj) {
						oCliked = null;
						src = oObj.attr('src'),
							onCheck = /\_on\.png$/,
							offCheck = /\_off\.png$/;
						$.getJSON('../include/toggle.php', {'sAction': 'toggle',
															'sField': oObj.attr('sField'),
															'sValue': (src.match(onCheck) ? 0 : 1),
															'iView': '$iView',
															'sTable': '',
															'sViewItemLink': '$sViewItemLink',
															'sAPP': '$sAPP'	}, function (json) {
							if (json[0].sAction=='toggle' && json[0].sError=='') { 
								if(src.match(onCheck)) {
									oObj.attr('src', src.replace(onCheck, '_off.png'));
								} else if (src.match(offCheck)) {
									oObj.attr('src', src.replace(offCheck, '_on.png'));
								}
							} else { 
								alert ('Error: ' + json[0].sError);
							} 		
						})
					}; " . ($sAction == 'edit' ? "
					
					$('#iDipartimento').change( function() {
						$.getJSON('select.php', {'sSource': 'iDipartimento', 'iDipartimento': $(this).val(), 'iShowAllResources': 1, 'sViewItemLink': '$sViewItemLink' }, function(json) {										
							var sOptions = '';
							for (var i = 0; i < json.length; i++) {
								sOptions += '<option value=\'' + json[i].iOptionValue + '\'>' + json[i].sOptionDisplay + '</option>';
							}
							$('#iUnita').html(sOptions);
							$('#iUnita option:first').attr('selected','selected');
						});
					});
					
					$('#iUnita').change( function() {
						$.getJSON('select.php', {'sSource': 'iUnita', 'iUnita': $(this).val(), 'iShowAllResources': 1, 'sViewItemLink': '$sViewItemLink' }, function(json) {										
							$('#iDipartimento option[value='+json[0].iOptionValue+']').attr('selected', 'selected');
						});
					});
					
					$('#sApparecchiatura').autocomplete({
						source: './civab.php',
						minLength: 3,
						select: function(event, ui) {
							$(this).val(ui.item.value);
							$('#sCivab').val(ui.item.sCivab);
						}
					}); " : '') . "	
		    
				});
				
			</script> ";
	
		return $sHeadContent;
	}

?>